import React from 'react'
const asyncComponent = loadComponent => (
  class MyComponent extends React.Component {
      state = {
        AnotherComponent: null
      };
      componentDidMount() {
        loadComponent()
        .then(res => res.default)
        .then(AnotherComponent => {
          this.setState({ AnotherComponent });
        }).catch(err => {
          new Error('loadComponent  is error :' + err)
        });
      }
      render() {
        let {AnotherComponent} = this.state;
        if (!AnotherComponent) {
          return <div style={{fontSize:'.32rem',color:'#333',textAlign:'center'}}>Loading...</div>;
        } else {
          return <AnotherComponent/>;
        }
      }
    }
);

export default asyncComponent;
